package com.java.androidmarket.utils;

import org.springframework.util.DigestUtils;

import java.util.Random;

/**
 * description:
 * author:张腾
 * date:2021-07-13
 */
public class MD5Utils {

    public static String getMD5(String str) {
        String salt = getSalt(8);
        String base = str + "/" + salt;
        String md5 = DigestUtils.md5DigestAsHex(base.getBytes());
        return md5;
    }
    public static String getSalt(int n){
        char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890~!@#$%^&*()_+".toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char aChar = chars[new Random().nextInt(chars.length)];
            sb.append(aChar);
        }
        return sb.toString();
    }
}
